#!/usr/bin/env python

import os, sys, glob

developargs = ""

def setPath(path):
    # Put the plugin directory in the environment so that setuptools won't barf
    # when placing the eggs into a non-syntem directory
    os.environ['PYTHONPATH'] = path
    
    global developargs
    developargs = "--install-dir %s" % path

topdir = os.getcwd()

# If this directory is a subdirectory of the subversion repository, the
# setuptools easy-install.pth can be installed right here and peppy will
# automatically load the plugins.  Otherwise, it will put the links in the
# global site-packages directory.

testfile = os.path.normpath(os.path.join(topdir, "../peppy/main.py"))
print testfile
if os.path.exists(testfile):
    setPath(topdir)


def process(path):
    if os.path.isfile(os.path.join(path, "setup.py")):
        print("processing %s" % path)
        os.chdir(path)
        os.system("python setup.py develop %s" % developargs)
    else:
        print("skipping non-plugin dir %s" % path)

dirs = os.listdir(topdir)
for d in dirs:
    os.chdir(topdir)
    if os.path.isdir(d):
        print("\n-----")
        process(d)
